<?

//Data loading
$title='DAFTAR KWITANSI';
 
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = GetCompany (GetOfficeID());
if (GetParam("location","")) $perush .= ' (DEPO: '.GetParam("location","").')';

$page   = 'PAGE';
$TableName = "ais_receipt";
$DEFINE_FONT=0;
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = ReportList ("", "", "");
if ($Result) $pdf->ReportTable($Result);
$pdf->Output();

function ReportList ($Space, $Index, $ParentID) {
		    global $RS,$Index,$TableName,$Curr;
		    $DBConnection   = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
			   if (!$Index) $Index = 0;

                  $SQL = "
							SELECT $TableName.*, date_format($TableName.tglkwit,'%d/%m/%y') as tgl 
                            FROM `$TableName` 
                            WHERE 1
                               ";
                  list($day,$month,$year) = explode("/",GetParam("fromDate",""));
                  $FDate = "$year-$month-$day";
                  list($day,$month,$year) = explode("/",GetParam("toDate",""));
                  $TDate = "$year-$month-$day";
                  $SQL .= " AND $TableName.tglkwit >= '$FDate' AND $TableName.tglkwit<='$TDate' ";
                  if (GetParam("location",""))
                    $SQL .= " AND $TableName.location = '".GetParam("location","")."' ";
				  if (GetParam("curr","")) 
	 				$SQL .= " AND curr='".GetParam("curr","")."' ";

                  $SQL .= " ORDER BY $TableName.nokwit, $TableName.tglkwit";
				 die($SQL);
                  $MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);
                  return $MyResult;
} 

class PDFReport extends PDF {

	function Header() {
		global $title,$perush,$page,$DEFINE_FONT;
		if ($DEFINE_FONT==0) {
			$this->AddFont('arialn','','arialn.php');
			$DEFINE_FONT=1;
		}
		$this->SetFont('arialn','',10);
        $this->Cell(195,5,$perush,0,1,'C',0);
        $this->Cell(195,5,$title,0,1,'C',0);
        $SystemDate = date("d/m/Y");
        $this->Cell(195,5,"PERIODE: ".GetParam("fromDate","")." S/D ".GetParam("toDate",""),0,1,'C',0);
        $this->Cell(195,5,$page." ".$this->PageNo(),0,1,'R',0);
        $this->Line(10,30,205,30);
        $this->Ln();
        //Header

        //Column widths
		$w=array(5,50,15,20,25,35,10,20,15);
        $this->SetFont('arialn','',8);
        $this->Cell($w[0],7,"NO",1,0,'C',0);
        $this->Cell($w[1],7,"NAMA DEBITUR",1,0,'C',0);
		$this->Cell($w[2],7,"DATE",1,0,'C',0);
        $this->Cell($w[3],7,"NO KWITANSI",1,0,'C',0);
        $this->Cell($w[4],7,"NO FAKTUR",1,0,'C',0);
        $this->Cell($w[5],7,"URAIAN",1,0,'C',0);
        $this->Cell($w[6],7,"CUR.",1,0,'C',0);
        $this->Cell($w[7],7,"JUMLAH",1,0,'C',0);
        $this->Cell($w[8],7,"SKADA",1,0,'C',0);
        $this->Ln();    	
	}

	function ReportTable($Result) {
	    //Column widths
        $w=array(5,50,15,20,25,35,10,20,15);
	    //Data
	    $TotalRow = 0;
	    foreach($Result as $row)
	    {
            if (strlen($row["debnam"])>20) 
				$row["debnam"] = substr($row["debnam"], 0, 20); 
			if ($LastNumber==$row["nokwit"]) {
				$this->Cell($w[0],5,"",'LR',0,'R');
				$this->Cell($w[1],5,"",'LR');
				$this->Cell($w[2],5,"",'LR',0,'C');
				$this->Cell($w[3],5,"",'LR',0,'C');
				$this->Cell($w[4],5,"",'LR',0,'L');			
			} else {
				$no++;
				$this->Cell($w[0],5,$no.".",'LR',0,'R');
				$this->Cell($w[1],5,$row["debnam"],'LR');
				$this->Cell($w[2],5,$row["tgl"],'LR',0,'C');
				$this->Cell($w[3],5,$row["nokwit"],'LR',0,'C');
				$this->Cell($w[4],5,$row["faktur"],'LR',0,'L');
			}
            $this->Cell($w[5],5,$row["uraian"],'LR',0,'L');
            $this->Cell($w[6],5,$row["curr"],'LR',0,'C');
            $this->Cell($w[7],5,FormatNumber($row["jumlah"]),'LR',0,'R');
            $this->Cell($w[8],5,$row["skada"],'LR',0,'R');
	        $this->Ln();
			$LastNumber = $row["nokwit"];
			$TotalRow = $TotalRow + $row["jumlah"];
	    }
				$this->Cell($w[0]+$w[1]+$w[2]+$w[3]+$w[4]+$w[5]+$w[6],5,"TOTAL ",'LTB',0,'R');
/*				$this->Cell($w[1],5,"TOTAL ",'TB');
				$this->Cell($w[2],5,"",'LR',0,'C');
				$this->Cell($w[3],5,"",'LR',0,'C');
				$this->Cell($w[4],5,"",'LR',0,'L');
        $this->Cell($w[5],5,"",'LR',0,'L');
        $this->Cell($w[6],5,"",'LR',0,'C'); */
        $this->Cell($w[7],5,FormatNumber($TotalRow),'LTB',0,'R');
        $this->Cell($w[8],5,"",'TBR',0,'R');
	      $this->Ln();
	    
	    //Closure line
	    //$this->Cell(array_sum($w),0,'','T');
	}

	function Footer() {
	    //Closure line
	    $this->Cell(195,0,'','T');
	}

}


?>
